import Vue from 'vue'
import axios from 'axios'
import utils from '@/utils/utils'

Vue.prototype.$axios = axios

// 数据接口API

export function requestApi (config) {
  const baseUrl = utils.setBaseUrl()
  console.log(baseUrl)
  // 创建实例
  const api = axios.create({
    baseURL: baseUrl,
    timeout: 60 * 1000
  })

  api.interceptors.request.use(
    (config) => {
      config.headers.siteId = 100
      // console.log(config)
      return config
    },
    (err) => {
      return Promise.reject(err)
    }
  )
  api.interceptors.response.use(
    (result) => {
      // console.log(result.data)
      return result.data
    },
    (err) => {
      return Promise.reject(err)
    }
  )

  return api(config)
}
